package com.romotc.qqrobot.webqq.qqInterfaceCall;

import java.util.ArrayList;

import net.sf.ehcache.search.attribute.JavaBeanAttributeExtractor;

import org.json.JSONException;
import org.json.JSONObject;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.scache.httpreq;

public class Get_file2_InterCall extends QQInterfaceCall {
	/**
	 * 消息ID
	 */
	public static final String Key_Must_Input_Lcid = "GetFileInterCall_lcid";
	/**
	 * 文件名
	 */
	public static final String Key_Must_Input_FileName = "GetFileInterCall_guid";
	/**
	 * 发送人Uin
	 */
	public static final String Key_Must_Input_SenderUin = "GetFileInterCall_to";
	
	@Override
	public String buildReqBody(JSONObject reqDataObj, QQLogedin loginQQ)
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int getLogLevel() {
		return 1001;
	}

	@Override
	public String getReqUrl(JSONObject reqDataObj, QQLogedin loginQQ)
			throws Exception {
		// http://d.web2.qq.com/channel/get_file2?lcid=29499&guid=%E5%90%8D%E7%89%87.jpg
				//&to=3664882061&psessionid=8368046764001d636f6e6e7365727665725f77656271714031302e3133342e362e31333800007f39000013a6036e0400d8e8885e6d0000000a406c784f6b69705543576d00000028bab08d56cd452fbd73ab007629e9a8a3ce5d1f4e6f0bc9fa8bd37ca9e7f12260c38b3ecca2e92117
				//&count=1&time=1326987487837&clientid=89778000
		// http://d.web2.qq.com/channel/get_file2?lcid=29498&guid=%E5%90%8D%E7%89%87.jpg
				//&to=3664882061&psessionid=8368046764001d636f6e6e7365727665725f77656271714031302e3133342e362e31333800007f39000013a6036e0400d8e8885e6d0000000a406c784f6b69705543576d00000028bab08d56cd452fbd73ab007629e9a8a3ce5d1f4e6f0bc9fa8bd37ca9e7f12260c38b3ecca2e92117
				//&count=1&time=1326987389779&clientid=89778000
		return "http://d.web2.qq.com/channel/get_file2?lcid="
					+ reqDataObj.getInt(Key_Must_Input_Lcid)
					+ "&guid=" + java.net.URLEncoder.encode(reqDataObj.getString(Key_Must_Input_FileName),"utf-8")//encode
					+ "&to=" + reqDataObj.getLong(Key_Must_Input_SenderUin)
					+ "&psessionid=" + loginQQ.getPsessionid()
					+ "&count=1&time=" + System.currentTimeMillis()
					+ "&clientid=" + loginQQ.getClientId();
	}

	@Override
	public int getReq_method() {
		return httpreq.REQUEST_GET;
	}

	@Override
	public boolean hasPreCall(QQLogedin loginQQ, JSONObject reqDataObj) {
		return false;
	}

	@Override
	public ArrayList<String> myReqHeaders(int reqBodyLen, QQLogedin loginQQ,JSONObject reqDataObj) {
		ArrayList<String> s = buildReqHeaders(loginQQ,
				"http://web.qq.com/", 
				"d.web2.qq.com");
		return s;
	}

	@Override
	public JSONObject preCall(QQLogedin loginQQ, JSONObject reqDataObj)
			throws Exception {
		return null;
	}
	
	
	
	public static void main(String[] args) {
		String name = "发送人.jpg";
		System.out.println(java.net.URLEncoder.encode(name));
		System.out.println(java.net.URLEncoder.encode(java.net.URLEncoder.encode(name)));
	}

	private static Get_file2_InterCall instance;
	public static synchronized Get_file2_InterCall getInstance() {
		if(instance == null)
			instance = new Get_file2_InterCall();
		return instance;
	}

}
